package com.cskaoyan.javase.file._4exercise;

/**
 * @description: String的intern方法
 * @author: wuguidong@cskaoyan.onaliyun.com
 **/

public class Demo {
    public static void main(String[] args) {
        String s1 = "Hello"; //存在字符串常量池
        String s2 = new String("Hello"); //堆上
        String s3 = new String("World"); //堆上
        String s4 = s2 + s3; //堆上
        System.out.println(s1 == s2.intern()); //true
        System.out.println(s2 == s2.intern()); //false
        System.out.println(s3 == s3.intern()); //false
        System.out.println(s4 == s4.intern()); //true

        //System.out.println(s5 == s4);
    }
}
